<?php
namespace TuxCocktail\TuxDb\Mysql\Cocktail;

use TuxCocktail\TuxDb\Mysql\TuxDbMysqlAbstract;
use TuxCocktail\TuxDb\Mysql\Cocktail\Model\ShakerTypeTable;
use TuxCocktail\TuxDb\TuxShakerTypeInterfafce;

class TuxDbMysqlShakerType extends TuxDbMysqlAbstract implements TuxShakerTypeInterfafce {

	/**
	 * 
	 * @var ShakerTypeTable
	 */
	private $shakerTypeTable;
	
	private function getShakerTypeTable() {
		
		if (!$this->shakerTypeTable) {
			$this->shakerTypeTable = new ShakerTypeTable($this->tuxDb->getInstance());
		}
		return $this->shakerTypeTable;
		
	}
	
	
	public function updateShakerTypeName($rowId,$value) {
		$this->getShakerTypeTable()->update(array('shaker_name'=>$value),array('shaker_type_id'=>$rowId));
	}
	
	public function updateShakerTypeDesc($rowId,$value) {
		$this->getShakerTypeTable()->update(array('shaker_desc'=>$value),array('shaker_type_id'=>$rowId));
	}
		
	public function getShakerTypeId($shakerTypeName) {
		$select = $this->getShakerTypeTable()->newSelect();
		$this->getShakerTypeTable()->getSelect($select,array('shaker_type_id'))->where(array('shaker_name'=>$shakerTypeName));
		$resultSet = $this->getShakerTypeTable()->selectWith($select);
		if ($resultSet->count() != 1) {
			return null;
		}
		$arr = $resultSet->toArray();
		return $arr[0]['shaker_type_id'];
	}
	
	public function getShakerTypeName($shakerTypeId) {
		$select = $this->getShakerTypeTable()->newSelect();
		$this->getShakerTypeTable()->getSelect($select,array('shaker_name'))->where(array('shaker_type_id'=>$shakerTypeId));
		$resultSet = $this->getShakerTypeTable()->selectWith($select);
		if ($resultSet->count() != 1) {
			return null;
		}
		$arr = $resultSet->toArray();
		return $arr[0]['shaker_name'];
		
	}
	
	public function getAllShakerTypes() {
		return $this->getShakerTypeTable()->fetchAll()->toArray();
	}
	
	
}